package com.peng.leetcode.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * IncreasingBST
 *
 * @author: lupeng6
 * @create: 2020/12/28 11:36
 */
public class IncreasingBST {

    public static void main(String[] args) {


    }

    public TreeNode increasingBST(TreeNode root) {
        List<Integer> list = new ArrayList();
        inOrder(root, list);
        if (list.isEmpty()) {
            return null;
        }
        TreeNode newRoot = new TreeNode(list.get(0));
        TreeNode dummy = newRoot;
        for (int i = 1; i < list.size(); i++) {
            newRoot.right = new TreeNode(list.get(i));
            newRoot = newRoot.right;
        }
        return dummy;
    }

    public static void inOrder(TreeNode root, List<Integer> list) {
        if (root == null) {
            return;
        }
        inOrder(root.left, list);
        list.add(root.val);
        inOrder(root.right, list);
    }
}
